package com.tom.poolsocket;

import java.io.PrintWriter;
import java.net.Socket;

/**
 * 客户端
 *
 * @author zx
 * @date 2024-09-24 20:50
 */
public class Client {
    public static void main(String[] args) {
        Socket socket = null;
        PrintWriter printWriter = null;
        try {
            // 创建客户端套接字对象
            socket = new Socket("127.0.0.1", 8080);
            printWriter = new PrintWriter(socket.getOutputStream(), true);
            // 获取输出流对象
            printWriter.write("hello world");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (socket != null) {
                try {
                    socket.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
